const {mysql} = require('../qcloud')

module.exports = async (ctx) => {
	const {openid} = ctx.request.query

	try {
		const res =  await mysql('records')
										.where('openid',openid)
										.orderBy('id','desc')
										.first()
		if (res) {
			var mark = res.mark
		} else {
			var mark = 0
		}
		// 执行成功返回到前端的数据，将最后这条记录的mark字段也传回到前端
		ctx.state.data = {
			code: 0,
			mark: mark,	//注意这行
			msg: 'success'
		}
		console.log('执行成功')
	} catch (err) {
		console.log('执行错误', err)
		// 执行失败返回到前端的数据
		ctx.state = {
			code: '-1',
			data: {
				msg: '获取失败' + err.sqlMessage
			}
		}
	}
}